<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE>
<html>
<head>
<meta charset=UTF-8>
<title></title>
<script src="${webroot }js/jquery.min.js"></script>
<script src="${webroot }js/bootstrap.min.js"></script>
<script src="${webroot }js/web.config.js"></script>
<script src="${webroot }js/func.action.js"></script>
<link rel="stylesheet" href="${webroot }css/bootstrap.min.css">
<link rel="stylesheet" href="${webroot }css/common.css">
<link rel="stylesheet" href="${webroot }css/client.css">
</head>
<body>
   <table class="table">
		<caption>
			<a data-toggle="modal" data-target="#myModal">添加教室</a>
		</caption>
		<thead>
			<tr>
				<td>编号</td>
				<td>教室号</td>
				<td>楼层</td>
				<td>规格</td>
				<td>操作</td>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${list }" var="cr">
				<tr>
					<td>${cr.crId }</td>
					<td>${cr.crNo }</td>
					<td>${cr.crFloor }</td>
					<td>${cr.crLength } X ${cr.crWidth }</td>
					
					<c:if test="${cr.crStatus!=1 }">
						<td><a href="#" onclick="updateCrStatus(${cr.crId},1)">启用</a>
							&nbsp;&nbsp;|&nbsp;&nbsp; <a href="#" onclick="delCr(${cr.crId},${cr.belongBu })">删除</a>
						</td>
					</c:if>
					<c:if test="${cr.crStatus==1 }">
						<td><a href="#" onclick="updateCrStatus(${cr.crId},2)">禁用</a>
							&nbsp;&nbsp;|&nbsp;&nbsp; <a href="#" onclick="delCr(${cr.crId},${cr.belongBu })">删除</a>
							&nbsp;&nbsp;|&nbsp;&nbsp; <a href="#" onclick="choDesk(${cr.crLength},${cr.crWidth },${cr.crId })">座位</a></td>
					</c:if>
					
				</tr>
			</c:forEach>
		</tbody>
	</table>
	
	<div class="info_footer">
		<div class="footer_con">

			<div class="btn-group dropup info_choose ">
				<span class="dropdown-toggle" id="status_menu" role="0"
					data-toggle="dropdown"> <c:if test="${status == 0 }">全部类型</c:if>
					<c:if test="${status == 1 }">激活状态</c:if> <c:if
						test="${status == 2 }">禁用状态</c:if>
				</span> <span class="caret"></span>
				<ul class="dropdown-menu" role="menu" id="status_item">
					<li><a href="${webroot }web/classroom/query?page=1&buId=${buId}&status=0">全部状态</a>
					</li>
					<li><a href="${webroot }web/classroom/query?page=1&buId=${buId}&status=1">激活状态</a>
					</li>
					<li><a href="${webroot }web/classroom/query?page=1&buId=${buId}&status=2">禁用状态</a>
					</li>
				</ul>
			</div>
			<div class="info_page">
				<ul class="pagination">
					<li><a id="pre_page" href="#">&laquo;</a></li>
					<li><a id="next_page" href="#">&raquo;</a></li>
				</ul>
				<div class="btn-group dropup">
					<button type="button" class="btn btn-default dropdown-toggle"
						id="page_menu" data-toggle="dropdown">
						第 ${page } 页<span class="caret"></span>
					</button>
					<ul class="dropdown-menu" role="menu" id="info_page">

					</ul>
				</div>
			</div>
		</div>
	</div>
	<div class="hidden_area">
		<input type="hidden" value="${page }" id="page"> 
		<input type="hidden" value="${pages }" id="pages"> 
		<input type="hidden" value="${status }" id="status">
		<input type="hidden" value="${buId }" id="buId">
		<input type="hidden" id="crId">
	</div>
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">添加教室</h4>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<label class="login_label">教室编号：</label> <input
							class="form-control login_input" id="focusedInput" type="text"
							placeholder="请输入教学楼名字" name="crNo">
					</div>
					<div class="form-group">
						<label class="login_label">所在楼层：</label> <input
							class="form-control login_input" id="focusedInput" type="number"
							placeholder="请输入教学楼名字" name="crFloor">
					</div>
					<div class="form-group">
						<label class="login_label">教室长：</label> <input
							class="form-control login_input" id="focusedInput" type="number"
							placeholder="请输入教学楼名字" name="crLength">
					</div>
					<div class="form-group">
						<label class="login_label">教室宽：</label> <input
							class="form-control login_input" id="focusedInput" type="number"
							placeholder="请输入教学楼名字" name="crWidth">
					</div>
				</div>
				<div class="modal-footer">
					<span id="res_msg"></span>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" id="sure" class="btn btn-primary">提交</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal -->
		</div>
		
	<div class="modal fade" id="desk" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">确定座位</h4>
				</div>
				<div class="modal-body" id="room">
					
				</div>
				<div class="modal-footer">
					<span id="res_msg"></span>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" id="desk_add" class="btn btn-primary">提交</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal -->
	</div>
		
	<script type="text/javascript">
		$(document).ready(function(){
			$("#sure").click(function(){
				var crNo = $("[name='crNo']").val();
				var crFloor = $("[name='crFloor']").val();
				var crLength = $("[name='crLength']").val();
				var crWidth = $("[name='crWidth']").val();
				var buId = $("#buId").val();
				$.ajax({
					url:webRoot + "web/classroom/add",
					type:"post",
					dataType:"json",
					data:{
						"crNo":crNo,
						"crFloor":crFloor,
						"crLength":crLength,
						"crWidth":crWidth,
						"belongBu":buId
					},
					success:function(data){
						if(data.result == "success"){
		    				alert("操作成功！请继续操作");
		    				$("[name='crNo']").val("");
		    				$("[name='crFloor']").val("");
		    				$("[name='crLength']").val("");
		    				$("[name='crWidth']").val("");
		    				location.reload();
		    			}else{
		    				alert("操作失败！");
		    			}
					}
				});
			});
				
			$("#pre_page").click(function(){
		   		var page = $("#page").val();
		   		var buId = $("#buId").val();
		   		if(page <= 1){
		   			alert("已经是第一页了");
		   		}else{
		   			var now = page - 1;
		   			var status = $("#status").val();
		   			window.location.href= webRoot + "web/classroom/query?page="+now+"&status="+status+"&buId="+buId;
		   		}
		   	});
		   	$("#next_page").click(function(){
		   		var page = $("#page").val();
		   		var pages = $("#pages").val();
		   		var buId = $("#buId").val();
		   		if(pages <= page){
		   			alert("已经是最后一页了");
		   		}else{
		   			var now = parseInt(page) + 1;
		   			var status = $("#status").val();
		   			window.location.href= webRoot + "web/classroom/query?page="+now+"&status="+status+"&buId="+buId;
		   		}
		   	});
		   	
		   	var page = $("#page").val();
		   	var pages = $("#pages").val();
		   	var status = $("#status").val();
		   	var buId = $("#buId").val();
		   	var doc_page = $("#info_page");
		   	doc_page.empty();
		   	for (var i = 0; i < pages; i++) {
		   		var cur = i + 1;
		   		if (i != (page - 1)) {
		   			doc_page.append("<li><a href='"+webRoot+"web/classroom/query?page="+cur+"&status="+status+"&buId="+buId+"'>第"+cur+"页</a></li>");
		   		}
		   	}
		   	$("#desk_add").click(function(){
		   		var roles = $("#room a[class='seat active selected']");
		   		if(roles.length == 0){
		   			alert("您未选择任何座位！");
		   		}else{
		   			var length = $("#room p").eq(0).find("a").length;
		   			var crId = $("#crId").val();
		   			var desk = "";
		   			for(i = 0 ; i < roles.length ; i++){
		    			desk = desk + roles.eq(i).attr("role");
		    			if(i < roles.length - 1){
		    				desk = desk + ",";
		    			}
		    		}
		   			$.ajax({
		   				url : webRoot+"web/desk/add",
		   				type:"post",
		   				dataType:"json",
		   				data:{
		   					"pos":desk,
		   					"length":length,
		   					"crId":crId
		   				},
		   				success:function(data){
		   					if(data.result == "success"){
		   						alert("添加成功！");
		   					}
		   				}
		   			});
		   		}
		   	});
		});
		</script>
</body>
</html>